package com.countryside.controller;

import com.countryside.pojo.EmployeeProject;
import com.countryside.pojo.EmployeeWork;
import com.countryside.pojo.User;
import com.countryside.service.EmployeeProjectService;
import com.countryside.service.impl.EmployeeProjectServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class EmployeeProjectController {
    @Autowired
    EmployeeProjectService employeeProjectService;

    /**
     * 添加用户项目经验
     * @param employeeProject
     * @param province
     * @param city
     * @param session
     * @return
     */
    @PostMapping("/addEmployeeProject")
    public String addEmployeeProject(EmployeeProject employeeProject,
                                     String province, String city,
                                     HttpSession session) {
        User user = (User) session.getAttribute("user");
        employeeProject.setUserId(user.getId());
        employeeProject.setProjectAddress(province + city);
        employeeProjectService.addEmployeeProject(employeeProject);
        return "redirect:user/getEmployeeWork";
    }

    /**
     * 删除用户项目经验
     * @param id
     * @return
     */
    @GetMapping("/deleteProject/{id}")
    public String deleteEmployeeProject(@PathVariable("id") int id) {
        employeeProjectService.deleteEmployeeProject(id);
        return "redirect:/user/getEmployeeWork";
    }



}
